#ifndef NR_DEVICE_ITEM_MANAGER_H
#define NR_DEVICE_ITEM_MANAGER_H

#include "nr_device_item_server.h"
#include "nr_device_type_manager.h"
#include "nr_io_manager.h"
#include <QtXml/QDomDocument>

class nr_device_item_manager
{
public:
    nr_device_item_manager(nr_device_type_manager& device_type_manager, nr_io_manager& io_manager);
    ~nr_device_item_manager();
    
    nr_error_t load();
    nr_error_t unload();
    
    nr_device_item_server& root_item() { return m_device_item_server; }

    nr_device_item* find_device_item_by_id(const nr_device_id_t &device_id);

    nr_error_t save_as_xml(const QString& xml_file);

private:
    //Parse the xml--"\\DeviceItems.xml"
    bool parse_device_item_server_parameters(QDomElement &node, nr_device_item_server &device_item_server);
    bool parse_device_group_parameters(QDomElement &node, nr_device_group &device_group);
    bool parse_device_item_paramaters(QDomElement &node, nr_device_item &device_item);
    bool parse_property_parameters(QDomElement &node, nr_device_property &device_property);
    bool analyze_property_node(QDomElement &property_node, nr_device_property &device_property);
    bool analyze_device_item_node(QDomElement &device_item_node, nr_device_item &deviceItem);
    bool analyze_device_group_node(QDomElement &device_group_node, nr_device_group &deviceGroup, nr_device_item &parent_deviceItem);

    nr_device_item_server m_device_item_server;
    nr_device_type_manager& m_device_type_manager;
    nr_io_manager& m_io_manager;    
};

#endif // NR_DEVICE_ITEM_MANAGER_H
